package com.process.service.impl;

import com.auth.model.process.ProcessTemplate;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.process.mapper.OaProcessTemplateMapper;
import com.process.service.OaProcessService;
import com.process.service.OaProcessTemplateService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

/**
 * <p>
 * 审批模板 服务实现类
 * </p>
 *
 * @author tang
 * @since 2023-07-23
 */
@Service
@Slf4j
public class OaProcessTemplateServiceImpl extends ServiceImpl<OaProcessTemplateMapper, ProcessTemplate> implements OaProcessTemplateService {


    private OaProcessService processService;


    /**
     * 获取分页审批模版列表
     *
     * @author Tangjiachang
     * @date 2023/7/23 14:52
     * @param processTemplatePage:
     * @return IPage<ProcessTemplate>
     **/
    @Override
    @Transactional(rollbackFor = Exception.class)
    public IPage<ProcessTemplate> selectPageProcessTemplate(Page<ProcessTemplate> processTemplatePage) {
        try {
            Page<ProcessTemplate> selectPage = baseMapper.selectPage(processTemplatePage, null);
            return selectPage;
        } catch (Exception e) {
            e.printStackTrace();
            //手工回滚异常
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        }
        return null;
    }

    /**
     * 发布流程
     *
     * @author Tangjiachang
     * @date 2023/7/23 16:00
     * @param id:
     * @return void
     **/
    @Override
    public String publish(Long id) {
        ProcessTemplate template = baseMapper.selectById(id);
        template.setStatus(1);
        baseMapper.updateById(template);
        return template.getProcessDefinitionPath();
    }
}
